package drg_group.taizhou_2022.MDC;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import drg_group.taizhou_2022.Base;
import drg_group.taizhou_2022.MedicalRecord;
import drg_group.taizhou_2022.ADRG.*;

public class MDCS{
    public static String group(MedicalRecord record){
        String[] mdc_zd={"B68.900x002","A49.800x019","B00.901","A48.400","B00.900x005","A48.800","B08.801","A68.000","B85.300","B52.000x002+N08.0*","A32.701","B04.x00","B08.800x006","B05.803","A59.001+N37.0*","A32.803","B01.900x002","A74.900","B33.300x001","B57.300","A31.000x004","A41.805","B00.900x007","A42.000","A49.300","B78.700","A51.000","B78.901","B48.400","B03.x00x004","B83.100","B81.802","A20.800x004","B08.400x003","B37.401+N37.0*","R68.801","A92.300x003","B05.800x009","B69.804","B46.800x001","Z03.000","A20.801","A19.902","B74.000x002","B83.000","A31.100x002","A75.000x002","A31.800x004","A67.200","B25.800x001","A56.001","A02.002","A52.709+N08.0*","B27.900x001","A31.802","B52.900x001","A31.002","A41.200","A79.801","A43.800x001","B18.103+N08.0*","B66.800x002","B05.802","A49.000","B05.801","A06.100x002","A02.901","A31.800x006","A49.808","A50.500","A67.900","B02.900x002","B03.x00x002","B79.x00","B83.201","A79.901","B57.100","B02.800x001","B71.000","B52.800","A06.200x001","A92.100","A38.x00x013","B38.900","B36.800","P37.300","A49.801","A48.100","B58.900x001","A38.x00","A41.000","B85.100","A23.300","B66.300x001","B83.800x004","A63.000","B38.800","B60.000x001","B33.802","A26.700x001","A20.200","A41.802","T85.700x809","B26.900x001","B88.300","A01.000x007","A19.901","A41.100x002","B67.600x001","A98.800","A02.000x009","A92.400","A31.900x001","B05.400","B83.000x002","A54.500","A23.000x001","A02.004","T85.712","A31.000","B36.801","A23.000","P37.000","A43.100","T81.400x005","A31.800x007","A20.803","A54.001","B66.800x003","A49.004","A18.813+D77*","B66.400","B65.101","A02.001","T81.406","A28.100","A06.800x002","A22.200","A22.700","A77.100x001","A41.502","A52.700x012+N08.0*","B42.100","B37.400x001+N37.0*","B27.000","B83.800x003","B69.800x008","B00.204","A97.900","B00.001","B08.000x001","A92.300x001","B39.300","A41.503","B88.900x003","A18.103+N29.1*","A01.000x004","A50.900","A49.805","A49.807","A99.x00","B41.800x001","B69.800x003","B01.800x004","B74.400x003","A27.900x005","A23.100","B39.500x001","B87.300","A93.200","B53.800x001","B88.800x004","A18.806+E35.0*","A18.200x010","A02.100","A18.700+E35.1*","A18.801+E35.8*","A93.000","B48.201","A02.000x006","T88.000","A51.002","A96.000","B27.100","A02.900x003","B42.100x003","B83.800x002","B50.800","B83.800x006","T82.700x005","A01.000x009","B38.700","B70.000","A49.100x005","B68.100","A48.800x002","A24.202","A75.900","A52.801","B34.400","B66.101","A41.807","B39.500","B49.x00x021","T85.706","A27.800","B26.800x004","A42.200x002","T86.807","A54.600x001","A26.700","A27.900x006","B76.901","B77.900","T80.200","B74.901","A02.100x002","A95.000","B83.000x001","T98.200x021","A40.903+N16.0*","B85.000","A06.300x001","A44.800","A40.200","A19.200","B37.700","B26.800x008+N08.0*","A36.900","A50.400x001","B67.601","B69.805","A41.500x087","B75.x00","B48.700","B02.900x001","B55.000","B71.900","B74.100x003","A32.900","A52.200","A50.700","A21.301","B51.800","B50.801","A01.000x010","A30.200","B81.800x002","A59.900","T85.700x103","A49.806","B55.100","B83.800x005","B88.900x002","A48.000","A49.803","A54.808","A56.200","A98.400","B67.906","T82.700x008","A02.000x010","B18.205+N08.0*","T81.400x004","A01.000x020","B34.000","B67.901","B69.800x004","B85.200","A24.100x002","A20.802","A27.900x004","B02.900x003","A22.100x003","A21.900x001","A31.800x003","A20.300","A49.100x006","B83.800x007","A42.803","A57.x00x003","T82.700x002","A51.300x003","B65.001","A30.000x001","B85.400","A51.302","B03.x00x003","B34.801","B66.200","B83.800x008","A18.105+N29.1*","T85.710","A19.900x004","A19.200x001","A50.401","B48.200","A02.101","A30.800","B77.800x002","B25.900x002","T79.300x001","A01.200","B50.000","A23.900x006","B45.700","A41.904+N16.0*","A56.301","B39.400","A68.100","B05.900x005","A77.100","A92.500","A98.500x001+N08.0*","A48.100x001","B49.x02+E35.8*","B55.000x001","B56.900x001","A92.300x004","A31.803","A42.900","A49.810","B49.x00x007","B69.803","A51.000x002","B65.100x001","A49.100x004","A42.200","A49.817","A77.000x001","B46.800x002","B37.800x088","A56.400","A51.300x004","B07.x00x009","A54.002","A41.101","B40.800","B34.102","B50.900x001","A41.505","A31.000x001","A30.100x001","A30.400x002","B33.801","A53.000x002","B37.808","B70.100","A06.700","A41.801","B34.200","B67.600x003","A23.800","B01.900x001","A63.001","A31.001","B48.000","A49.802","B65.200x001","A51.100x001","B34.400x002","B45.801","B53.000x001","T80.200x004","A24.300","B08.401","A26.900","B69.100","B48.800x001","A52.101","B37.801","A69.200","A31.000x005","A97.200","B55.200","A06.800x001","A67.300","B65.800x003","A24.201","B65.900x008","B81.801","A49.800x020","B74.200x001","A49.002","A18.700x002+E35.1*","A35.x00x001","B05.800x008","A77.800","A31.101","A28.801","A48.300","A49.804","A63.002","A97.100","B01.801","B65.800x002","T81.404","B33.800","T81.400x001","A98.200","B33.000","T81.400x006","A30.200x001","A31.100","A66.800","A79.800x002","A02.800","A49.001","B41.700","A49.812","A24.000x002","A49.900","B42.100x002","B45.100","A52.100","B57.200x003","A30.500","B74.902","A18.108+N33.0*","A26.800x001","A42.805","A19.900","B05.800x010","A96.100","B67.400x001","T82.700x010","A98.100","A41.504","A24.002","B76.900x003","A49.103","A59.000","A49.902","B44.800x005","A51.200","A51.400x001","A31.102","B57.500","B81.400","B78.000","A41.806","A70.x00","B66.800x005","A01.000","B44.100x003","B83.800x001","A75.100","B42.900","A66.600","B74.900x005","A42.802","A18.200x006","A20.101","A31.800x005","B40.900","B77.800x004","A36.900x002","A30.500x001","T82.700x004","A60.002","A51.001","B52.001+N08.0*","B54.x00x006","A30.900x004","T82.700x003","A01.400","B68.901","A98.300","B37.900","B34.100","B66.800x006","A01.100","B43.800","B45.900","B02.700","T82.700x001","A21.000","B27.800","A01.000x018","A02.003","O98.600x001","A95.900","A77.300x001","A92.900","B88.900x001","B27.001","B48.000x001","T81.401","A21.700","B60.800x001","A23.903+N16.0*","T85.711","A18.208","A96.900","A36.804+N16.0*","T85.703","A30.900x008","A54.602","B53.100","A06.000","B83.300","A48.801","A48.200","A77.300","A60.900","A96.800","T81.402","B76.800","B47.900","A52.700x001","B74.900x003","A18.100x021+N37.8*","A26.000","A44.900","A69.900","A38.x00x012","A49.102","A93.100","B77.803","B74.000x001","A95.100","B65.300","B77.800x005","B08.300","B33.000x001","B71.800","B83.800x009","B76.100","B44.802","B81.300","A06.001","B81.100","B66.800x007","B54.x00x004","A06.200","B08.000x002","A28.200","A54.601","A77.900","A06.900","A41.500x083","A53.900","B67.401","B00.205","B74.300","B08.100","A21.100","A21.300","A40.800","B69.800x005","B99.x01","T85.708","A06.000x001","A06.100","B40.700","A21.800x001","B66.100","A31.800x002","A22.900","B66.300","A20.100","B65.000x001","A02.000","A18.212","A52.300","A41.501","A01.000x014","B66.400x001","A48.100x003","A51.303","B34.800x004","A18.207","B57.200x001","A21.700x002","B42.100x001","A30.300x001","A18.107+N29.1*","A54.900x001","A75.300x001","A18.101","B83.200x001","B51.000","B60.000","A58.x00","A92.300","A54.809","B26.805+N08.0*","B65.900x007","A49.814","B49.x18","B67.905","A44.100","A41.900x004","A49.301","A21.300x002","A41.800x002","A51.900","A79.000","B74.800x001","A01.003","A18.100x031","A31.901","B51.900","A23.900x003","A98.000","A24.100x003","B08.800x004","B41.800x003","T82.700x007","A66.100","A42.700","A50.200","B34.800x003","A77.200x001","A92.800","B74.400x002","R50.803","T85.700x104","A20.700","A06.300","T81.400x002","A30.300x002","B65.800x001","T85.709","A30.900x005","B55.200x001","B74.200x003","B00.701","T84.701","A30.400x001","A22.000","B44.800x003","B58.801+N16.0*","A02.000x005","A63.800","A41.506","B46.400","B67.907","A25.100x001","A93.801","B76.000","B74.000x003","B47.100x001","A27.900x002","A41.900","B88.800x002","A19.100","A92.001","B67.903","A66.700","A30.400","B88.200x001","A49.800x015","A24.001","A30.100x003","A42.800x002","A64.x00","B26.800x011","B65.900x006","B74.100x001","B83.900","B87.100","B88.000x002","A92.300x002","T82.700x011","B68.900x004","A49.901","A20.800x005","A75.200x001","A19.900x005","A23.900x001","B67.902","A31.800x001","A24.102","A01.000x008","A96.100x001","A24.000","A40.300","B05.901","B34.101","B42.700","A25.900","A79.100","A51.300x005","B69.801","A58.x01","B66.500","B83.200x003","A41.804","B87.900","T81.405","B69.900x001","B99.x00x001","A28.001","A42.100","A20.000x001","B67.700x001","B81.200","A40.000","A40.100","B67.600x002","A18.104+N29.1*","A66.000","B41.900","A54.900","A57.x00x002","B42.800","B89.x00","B90.102+N29.1*","B89.x01","A77.000","B26.800x010","B33.100","B74.900","B49.x11","B66.901","A94.x01","A43.801","A06.002","B48.300x001","B71.100","A52.100x011","A54.100x002","B18.904+N08.0*","A44.000","B48.300","A49.800x003","A41.400","A18.106+N29.1*","R50.801","A50.100","B43.100","B81.800x001","B43.900","A50.500x001","B00.700","B05.900x001","B74.100x002","B64.x00","B68.900x003","A30.900","B54.x00x008","A51.300x002","B37.800x085","B39.400x001","A77.900x001","A49.201","A27.800x001","A02.900x004","A52.900","A23.200","A55.x00","A66.400","B56.100x001","T85.701","A26.900x002","B55.900","A78.x00","B55.100x001","B66.900","A66.900","A02.900x002","A18.211","A67.100","B08.000x004","A23.900x004","A50.600","A01.000x006","B34.400x001","A31.801","A67.000","A56.302","B34.800x002","A01.000x017","A50.000","A53.000x001","A49.815","A49.800x014","R50.900x002","R50.901","B34.300x002","A38.x00x014","B08.200x002","B76.902","B08.200","A49.813","A75.000x003","B44.801","B88.000x003","R50.900","P37.100","B67.302+E35.0*","A22.200x001","A43.900","B44.900x001","B46.500","B74.400x001","A43.802","A36.800x005+N33.8*","B88.100","B67.904","A92.000","B51.000x001+D77*","A32.000","B47.000","T85.702","B34.900","R50.800x002","B46.100x001+G99.8*","B69.802","T82.700x009","A56.800","A18.206","B00.902","A40.900","B66.800x001","B67.301","A25.000x001","A38.x00x011","A65.x00","B25.900x001","B47.100","A20.000","A01.000x011","A69.800","T80.201","B06.900x001","B66.902","A49.800x023","B48.401","A49.200","A51.301","A51.201","B81.000","A42.801","B83.400","A66.300","A75.000x004","A41.400x001","A18.209","A49.003","B49.x00x013","B87.800x001","B55.000x003","A49.811","B88.800x001","B78.902+N08.0*","R50.802","A50.400","A30.300","A56.000x003","B05.900x002","A66.200","A18.100x025+N29.1*","T98.200x012","A51.400x010","A38.x00x010","A28.900","B39.900","B48.402","B66.000x001","T81.403","A51.304","B03.x00","A77.200","A28.000","A30.900x002","B66.000","A01.000x019","A21.800","B80.x00","A27.000","B44.700","B37.802","B37.901","A01.000x012","B46.900x002","B01.800x002+N08.0*","A93.802","B56.000x001","A49.101","B34.300","B68.000","A23.100x001","A01.300","A32.700","A51.500","B45.800x002","B76.900","T85.700x808","A02.000x007","A41.300","A42.804","A24.101","A56.300x001","A96.200","A18.210","B73.x00","B74.400","J10.800x002","A97.000","B26.804","A18.800x001","A30.900x003","A60.001","A92.200","A59.800x001","B37.700x001","B00.202","A18.100x022+N37.8*","A75.001","B43.801","B52.000","A06.800x003","A20.900x002","A68.900","A54.900x002","A98.400x001","T82.701","A52.800","B66.800x004","A41.803","A63.003","A24.400","B65.905+N08.0*","A79.900","B74.200x002"};
        String[] dept_list={};
        if (!(true && Base.contains(mdc_zd,record.zdList[0]))){
            return "";
        }
        
        Base.groupMessages.putMessage(record.Index,"符合MDCS入组条件，匹配规则：主诊断匹配");
        String result;

        result=SB1.group(record);
        if (result.length()>0){
            return result;
        }

        if (false && record.ssList!=null && record.ssList.length>0  && Base.intersect(Base.SS_VALID,record.ssList)){
            Base.groupMessages.putMessage(record.Index,"符合SQY入组条件，存在有效手术操作："+String.join(",",Base.Intersect(record.ssList,Base.SS_VALID)));
            return "SQY";
        }

        result=SR1.group(record);
        if (result.length()>0){
            return result;
        }

        result=SS1.group(record);
        if (result.length()>0){
            return result;
        }

        result=ST1.group(record);
        if (result.length()>0){
            return result;
        }

        result=SU1.group(record);
        if (result.length()>0){
            return result;
        }

        result=SV1.group(record);
        if (result.length()>0){
            return result;
        }

        result=SZ1.group(record);
        if (result.length()>0){
            return result;
        }

        Base.groupMessages.putMessage(record.Index,"不符合MDCS的ADRG入组条件");
        return "";
    }
}

